package com.bruce.codeFactory.Thread.designMode.CountDown;

import java.util.concurrent.CountDownLatch;
import java.util.stream.IntStream;

/**
 * @author luotuan
 * @Description
 * @create 2019-03-07 22:34
 **/
public class CountDownCilent {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(5);
        System.out.println("开始线程任务");
        IntStream.rangeClosed(1,5).forEach(i->{
            new Thread(()->{
                System.out.println(Thread.currentThread().getName()+" is working");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                countDownLatch.countDown();
            },String.valueOf(i)).start();
        });
        countDownLatch.await();
        System.out.println("=========================================");
        System.out.println("开始做其他事情");
    }
}
